Problem Solving in Data Structures & Algorithms Using C by Hemant Jain
Author:Hemant Jain [Jain, Hemant]
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2017-07-14T04:00:00+00:00
Nth Pre-Order
Solution: We want to print the node that will be at the nth index when we print the tree in PreOrder traversal. Therefore, we keep a counter to keep track of the index. When the counter is equal to index, then we print the value and return the Nth PreOrder index node.
Example 10.8:
1. treePtr NthPreOrder(treePtr root, int index)/* pre order */
2. {
3. static int counter=0;
4. treePtr temp=NULL;
5. if(root)
6. {
7. counter ++;
8. if(counter == index)
9. {
10. printf(" %d ", root->value);
11. return root;
12. }
13. temp=NthPreOrder(root->lChild,index);
14. if(temp)
15. return temp;
16. temp=NthPreOrder(root->rChild,index);
17. if(temp)
18. return temp;
19. }
20. return NULL;
21. }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8310)
Test-Driven Development with Java by Alan Mellor(6818)
Data Augmentation with Python by Duc Haba(6731)
Principles of Data Fabric by Sonia Mezzetta(6476)
Learn Blender Simulations the Right Way by Stephen Pearson(6385)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6248)
Hadoop in Practice by Alex Holmes(5966)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5816)
RPA Solution Architect's Handbook by Sachin Sahgal(5648)
Big Data Analysis with Python by Ivan Marin(5405)
The Infinite Retina by Robert Scoble Irena Cronin(5339)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5161)
Pretrain Vision and Large Language Models in Python by Emily Webber(4371)
Infrastructure as Code for Beginners by Russ McKendrick(4140)
Functional Programming in JavaScript by Mantyla Dan(4044)
The Age of Surveillance Capitalism by Shoshana Zuboff(3964)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3853)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3656)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3632)
